package mi919;

import java.util.Scanner;

/**
 * @author tmh
 * @date 2024/9/19 17:05
 * @description
 */
public class T2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        while (num > 0) {
            int len = scanner.nextInt();
            int[] a1 = new int[len];
            int[] b1 = new int[len];
            for (int i = 0; i < len; i++) {
                a1[i] = scanner.nextInt();
            }
            for (int i = 0; i < len; i++) {
                b1[i] = scanner.nextInt();
            }
            //分别对a1纯判断是否递增/递减
            boolean result = false;
            boolean[] dp1 = new boolean[len];
            boolean[] dp2 = new boolean[len];
            boolean[] dp3 = new boolean[len];
            boolean[] dp4 = new boolean[len];

            dp1[0] = true;
            dp2[0] = true;
            //对a1的判断
            for (int i = 1; i < len; i++) {
                //看是否可以递增
                if (a1[i] < a1[i - 1]) {
                    if (b1[i] > a1[i - 1]) {
                        dp1[i] = dp1[i - 1] == true ? true : false;
                    }
                }
            }
            for (int i = 1; i < len; i++) {
                //看看是否可以递减
                if (a1[i] > a1[i - 1]) {
                    if (b1[i] < a1[i - 1]) {
                        dp2[i] = dp2[i - 1] == true ? true : false;
                    }
                }
            }

            //b1的判断
            for (int i = 1; i < len; i++) {
                //看是否可以递增
                if (b1[i] < b1[i - 1]) {
                    if (a1[i] > b1[i - 1]) {
                        dp3[i] = dp3[i - 1] == true ? true : false;
                    }
                }
            }

            for (int i = 1; i < len; i++) {
                //看看是否可以递减
                if (b1[i] > b1[i - 1]) {
                    if (a1[i] < b1[i - 1]) {
                        dp4[i] = dp4[i - 1] == true ? true : false;
                    }
                }
            }
            if (dp1[len - 1] || dp2[len - 1] || dp3[len - 1] || dp4[len - 1]) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
            num--;
        }


    }
}
